/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.agh.io.gpstracker.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author wkedzior
 */
@Entity
@Table(name = "user")
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findById", query = "SELECT u FROM User u WHERE u.id = :id"),
    @NamedQuery(name = "User.findByLogin", query = "SELECT u FROM User u WHERE u.login = :login"),
    @NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password"),
    @NamedQuery(name = "User.findByName", query = "SELECT u FROM User u WHERE u.name = :name"),
    @NamedQuery(name = "User.findBySurename", query = "SELECT u FROM User u WHERE u.surename = :surename"),
    @NamedQuery(name = "User.findByType", query = "SELECT u FROM User u WHERE u.type = :type")})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "login")
    private String login;
    @Basic(optional = false)
    @Column(name = "password")
    private String password;
    @Column(name = "name")
    private String name;
    @Column(name = "surename")
    private String surename;
    @Column(name = "type")
    private Short type;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Track> trackSet;
    
    
/*    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Position> positionSet;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Area> areaSet;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Track> trackSet;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Way> waySet;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<User> userSet;
    @JoinColumn(name = "master_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private User user;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Messages> messagesSet;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user1")
    private Set<Messages> messagesSet1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Userplaces> userplacesSet;*/

    public Set<Track> getTrackSet() {
		return trackSet;
	}

	public void setTrackSet(Set<Track> trackSet) {
		this.trackSet = trackSet;
	}

	public User() {
    }

    public User(Integer id) {
        this.id = id;
    }

    public User(Integer id, String login, String password) {
        this.id = id;
        this.login = login;
        this.password = password;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurename() {
        return surename;
    }

    public void setSurename(String surename) {
        this.surename = surename;
    }

    public Short getType() {
        return type;
    }

    public void setType(Short type) {
        this.type = type;
    }

  /*  public Set<Position> getPositionSet() {
        return positionSet;
    }

    public void setPositionSet(Set<Position> positionSet) {
        this.positionSet = positionSet;
    }

    public Set<Area> getAreaSet() {
        return areaSet;
    }

    public void setAreaSet(Set<Area> areaSet) {
        this.areaSet = areaSet;
    }

    public Set<Track> getTrackSet() {
        return trackSet;
    }

    public void setTrackSet(Set<Track> trackSet) {
        this.trackSet = trackSet;
    }

    public Set<Way> getWaySet() {
        return waySet;
    }

    public void setWaySet(Set<Way> waySet) {
        this.waySet = waySet;
    }

    public Set<User> getUserSet() {
        return userSet;
    }

    public void setUserSet(Set<User> userSet) {
        this.userSet = userSet;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Set<Messages> getMessagesSet() {
        return messagesSet;
    }

    public void setMessagesSet(Set<Messages> messagesSet) {
        this.messagesSet = messagesSet;
    }

    public Set<Messages> getMessagesSet1() {
        return messagesSet1;
    }

    public void setMessagesSet1(Set<Messages> messagesSet1) {
        this.messagesSet1 = messagesSet1;
    }

    public Set<Userplaces> getUserplacesSet() {
        return userplacesSet;
    }

    public void setUserplacesSet(Set<Userplaces> userplacesSet) {
        this.userplacesSet = userplacesSet;
    }
*/
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.edu.agh.io.gpstracker.model.User[id=" + id + "]";
    }

}
